package com.achievo.know.domain;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import com.dayatang.domain.BaseEntity;
import com.dayatang.domain.InstanceFactory;

@Entity
@Table(name="RAMS_FAQ")
public class Faq extends BaseEntity{

	/**
	 * 
	 */
	private static final long serialVersionUID = 3613493377677480811L;

	//评论内容
	@NotNull
	@Column(name="CONTENT",length=2000,nullable=false)
	private String content;
	
	//用户
	@NotNull
	@Column(name="USER_NAME",nullable=false,length=20)
	private String user;
	
	@Column(name="FAQ_FROM")
	private int from;
	
	@Column(name="FK_ID")
	private Long fkId;
	
	//发表时间
	@Column(name="PUBLISH_TIME",nullable=false)
	@Temporal(TemporalType.TIMESTAMP)
	private Date publishTime;
	
	//父
	@ManyToOne
	@JoinColumn(name="FK_PARENT_ID")
	private Faq parent;
	
	//子
	@OneToMany(fetch=FetchType.LAZY,cascade=CascadeType.REMOVE)
	@JoinColumn(name="FK_PARENT_ID")
	private List<Faq> children;
	
	@Transient
	private String title;
	
	@Column(name="CATEGORY_ID")
	private Long categoryId;
	
	
	

	public Long getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(Long categoryId) {
		this.categoryId = categoryId;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	public Date getPublishTime() {
		return publishTime;
	}

	public void setPublishTime(Date publishTime) {
		this.publishTime = publishTime;
	}

	public Faq getParent() {
		return parent;
	}
	

	public int getFrom() {
		return from;
	}

	public void setFrom(int from) {
		this.from = from;
	}

	public Long getFkId() {
		return fkId;
	}

	public void setFkId(Long fkId) {
		this.fkId = fkId;
	}

	public void setParent(Faq parent) {
		this.parent = parent;
	}

	public List<Faq> getChildren() {
		return children;
	}

	public void setChildren(List<Faq> children) {
		this.children = children;
	}

	@Override
	public boolean equals(Object arg0) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return 0;
	}
	
	private static FaqRepository faqRepository;

	public static FaqRepository getFaqRepository() {
		if (faqRepository == null) {
			faqRepository = InstanceFactory.getInstance(FaqRepository.class);
		}
		return faqRepository;
	}
	
	
}
